package com.hyjx.framework.common.util;

import com.hyjx.framework.common.CommonUtil;
import com.hyjx.framework.orm.dao.Pager;

import java.util.List;

/**
 * 分类列表工具类
 *
 * @author dijian
 */
public class DataGrideUtil {
    /**
     * 通过数据列表返回json字符串
     *
     * @param list 数据列表
     * @return
     */
    public static String getDataGridJsonByList(List list) {
        StringBuffer sb = new StringBuffer();
        sb.append("{");
        sb.append("\"total\": " + list.size() + ",");
        sb.append("\"rows\": ");
        sb.append(CommonUtil.getJsonString(list));
        sb.append("}");
        return sb.toString();
    }

    /**
     * ͨ通过pager对象返回json字符串
     *
     * @param pager
     * @return
     */
    public static String getDataGridJsonByPager(Pager pager) {
        StringBuffer sb = new StringBuffer();
        sb.append("{");
        sb.append("\"total\": " + pager.getRowCount() + ",");
        sb.append("\"rows\": ");
        sb.append(CommonUtil.getJsonString(pager.getResultList()));
        sb.append("}");
        return sb.toString();
    }
}
